##
# This class handles the login of users
class UserController < ApplicationController
  model   :user
  layout  'scaffold'

  ##
  # this method logs the user in
  def login
    case @request.method
      when :post
        if session['user'] = User.authenticate(params['user_login'], params['user_password'])

          flash[:notice]  = "Login successful"
          redirect_to :action => "welcome"
        else
          @login    = params['user_login']
          @message  = "Login unsuccessful"
      end
    end
  end
  
  ##
  # this method sings a new user up.
#  def signup
#    case @request.method
#      when :post
#        @user = User.new(params['user'])
#        
#        if @user.save      
#          session['user'] = User.authenticate(@user.login, params['user']['password'])
#          flash[:notice]  = "Signup successful"
#          redirect_back_or_default :action => "welcome"          
#        end
#      when :get
#        @user = User.new
#    end      
#  end  
  
  ##
  # this method deletes an user
#  def delete
#    if params['id'] and session['user']
#      @user = User.find(params['id'])
#      @user.destroy
#    end
#    redirect_back_or_default :action => "welcome"
#  end  
    
  ##
  # this method logs the currently logged in user out
  def logout
    session['user'] = nil
  end
    
  ##
  # this method redirects to the dashboard
  def welcome
  	redirect_to :controller => "dashboard"
  end
  
end
